<?php
class CtableHelper extends AppHelper {
   var $helpers = array('Html');
    /** ********************************************************************************
     * bang: de hien thi
     * ********************************************************************************/	
    
  
    
  function doanph($model,$cot,$dong,$data=array(),$dathu=array(),$doanphi=array(),$url=array(),$users=array(),$border=0){
    $n=count($cot);
    $m=count($dong);
    $kq='<input type="hidden" id="doanvien" value="'.$m.'" />';
    $kq.='<table id="tables" border='.$border.'>';  
    //for($i=-1;$i<$m;$i++){
    
    $kq.='<tr>';
	$kq.='<th rowspan="2">STT</th>';
    $kq.='<th rowspan="2">Họ Tên</th>';
    $kq.='<th colspan="12">Tháng</th>';
    $kq.='</tr>';
    
    //$kq=$kq. '<th>Tháng</th>';
               
            
    foreach($cot as $k=>$c):
  
    	if (empty($doanphi[$k]))
         {
         	$doanp=0;
         }
         else
         {
         	$doanp=$doanphi[$k];
         }
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'<br> ('. number_format($doanp,0,',','.').')</font></b>
                      <input type="checkbox" class="checkall" id='.$k.'></input></th>';
                      
		$kq=$kq. '<input type="hidden" id="thang'. $k .'" value="'.$doanp.'" />';
                      
   endforeach; 
  
    $i=0;
	$j=1;
    foreach ($dong as $key=>$d):
        $kq.='<tr>';
        
        $kq.='<td>'.$j++.'</td>';
            $kq.='<td>'.$d.'</td>';
            foreach($cot as $k=>$c):
            
            //ghep id cua thang_mssv vao value
            //kiem tra nếu đã có dữ liệu, tức là có đóng đoàn phí thì check vào
                  if(in_array($k.'_'.$key,array_keys($data)))            
                  {
                  	$kq .= "<td style='text-align: left;'>- ".date('d-m-Y',strtotime($data[$k.'_'.$key]))."<br>-".$users[$k.'_'.$key]."<br>- <a href='".$this->webroot.$url['controller']."/".$url['action']."/".$k."_".$key.'/'.$url['params']."' >Xóa </a>"."</td>";
                  	//$kq .='<input type="hidden" id="check'.$k.'_'.$i.'" value="'.$k.'_'.$key.'"></input></td>';
                  }
                  else
                    $kq=$kq. '<td><input type="checkbox" class="check" id="check'.$k.'_'.$i.'" name="data['.$model.'][dadong][]" value="'.$k.'_'.$key.'">
                      </input></td>';
                  
                  
            endforeach;  
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    $kq.='<tr>';
    $kq.='<td colspan="2"><b>Tổng Đoàn Phí Tháng</b></td>';
    $tong = 0;
     foreach($cot as $k=>$c):
       $kq=$kq. '<td id= tong'. $k .' style="text-align: center;">'. (empty($dathu[$k])?0:number_format($dathu[$k],0,',','.')) .'</td>';
       $kq=$kq. '<input type="hidden" id="dathu'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $kq=$kq. '<input type="hidden" id="dt'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $tong += empty($dathu[$k])?0:$dathu[$k];
     endforeach; 
    $kq.=' </tr>';
    $kq.='<tr>';
    $kq.='<td colspan="2"><strong>Tổng Đoàn Phí Năm Học</strong></td>';
       $kq=$kq. '<td id="tongtd" style="text-align: center;" colspan='.$n.' >'.number_format($tong,0,',','.').'</td>';
       $kq=$kq. '<input type="hidden" id="tong"  value="'. $tong .'" />';
    $kq.=' </tr>';
    $kq.='</table>';
    return $kq;
  }

  function doanphexcel($model,$cot,$dong,$data=array(),$dathu=array(),$doanphi=array(),$users=array(),$border=0){
    $n=count($cot);
    $m=count($dong);
    $kq='<input type="hidden" id="doanvien" value="'.$m.'" />';
    $kq.='<table id="tables" border='.$border.'>';  
    //for($i=-1;$i<$m;$i++){
    
    $kq.='<tr>';
	$kq.='<th rowspan="2">STT</th>';
    $kq.='<th rowspan="2">Họ Tên</th>';
    $kq.='<th colspan="12">Tháng</th>';
    $kq.='</tr>';
    
    //$kq=$kq. '<th>Tháng</th>';
               
            
    foreach($cot as $k=>$c):
  
    	if (empty($doanphi[$k]))
         {
         	$doanp=0;
         }
         else
         {
         	$doanp=$doanphi[$k];
         }
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'<br> ('. number_format($doanp,0,',','.').')</font></b></th>';                      
   endforeach; 
  
    $i=0;   
	$j=1;
    foreach ($dong as $key=>$d):
        $kq.='<tr>';
        
           $kq.='<td>'.$j++.'</td>';
            $kq.='<td>'.$d.'</td>';
            foreach($cot as $k=>$c):
            
            //ghep id cua thang_mssv vao value
            //kiem tra nếu đã có dữ liệu, tức là có đóng đoàn phí thì check vào
                  if(in_array($k.'_'.$key,array_keys($data)))            
                  {
                  	//$kq .= "<td style='text-align: center;'>".date('d-m-Y',strtotime($data[$k.'_'.$key]))."</td>";
                  	$kq .= "<td style='text-align: left;'>- ".date('d-m-Y',strtotime($data[$k.'_'.$key]))."<br>-".$users[$k.'_'.$key]."</td>";
                  }
                  else
                  	$kq .= "<td></td>";
            endforeach;  
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    $kq.='<tr>';
    $kq.='<td colspan="2"><b>Tổng Đoàn Phí Tháng</b></td>';
    $tong = 0;
     foreach($cot as $k=>$c):
       $kq=$kq. '<td id= tong'. $k .' style="text-align: center;">'. (empty($dathu[$k])?0:number_format($dathu[$k],0,',','.')) .'</td>';
       $kq=$kq. '<input type="hidden" id="dathu'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $kq=$kq. '<input type="hidden" id="dt'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $tong += empty($dathu[$k])?0:$dathu[$k];
     endforeach; 
    $kq.=' </tr>';
    $kq.='<tr>';
    $kq.='<td colspan="2"><strong>Tổng Đoàn Phí Năm Học</strong></td>';
       $kq=$kq. '<td id="tongtd" style="text-align: center;" colspan='.$n.' >'.number_format($tong,0,',','.').'</td>';
       $kq=$kq. '<input type="hidden" id="tong"  value="'. $tong .'" />';
    $kq.=' </tr>';
    $kq.='</table>';
    return $kq;
  }
  
  function doanphkhoa($model,$cot,$dong,$data=array(),$dathu=array(),$doanphi=array(),$url=array(),$soluong=array(),$tongtiens=array()){
	$n=count($cot);
    $m=count($dong);
    $kq='<input type="hidden" id="chidoan" value="'.$m.'" />';
	
    foreach ($soluong as $keysl => $valuesl) 
     {
     	$kq .='<input type="hidden" name=data['.$model.'][chidoan]['.$keysl.'] id="'.$keysl.'" value="'.$valuesl.'"></input>';
     }
     
    $kq.='<table id="tables">';  
    //for($i=-1;$i<$m;$i++){
    
    $kq.='<tr>';
	$kq.='<th rowspan="2">STT</th>';
    $kq.='<th rowspan="2">Chi đoàn</th>';
    $kq.='<th rowspan="2" style="text-align: center;">Đã đóng</th>';
    $kq.='<th colspan="12" style="text-align: center;">Tháng</th>';
    $kq.='</tr>';
    
    //$kq=$kq. '<th>Tháng</th>';
               
    foreach($cot as $k=>$c):
  
    	if (empty($doanphi[$k]))
         {
         	$doanp=0;
         }
         else
         {
         	$doanp=$doanphi[$k];
         }
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'<br> ('. number_format($doanp,0,',','.').')</font></b>
                      <input type="checkbox" class="checkall" id='.$k.'></input></th>';
                      
		$kq=$kq. '<input type="hidden" id="thang'. $k .'" value="'.$doanp.'" name=data['.$model.'][doanphithang]['.$k.'] />';
                      
   endforeach; 
  
    $i=0;   
	$j=1;
    foreach ($dong as $key=>$d):
        $kq.='<tr>';
            $kq.='<td>'.$j++.'</td>';
            $kq.='<td>'.$d.' <br> ( <b>'.$soluong[$key].'</b> đoàn viên)</td>';
            $kq.='<td>'.(isset($tongtiens[$key])?number_format($tongtiens[$key],0,',','.'):0).'</td>';
            foreach($cot as $k=>$c):
            
            //ghep id cua thang_mssv vao value
            //kiem tra nếu đã có dữ liệu, tức là có đóng đoàn phí thì check vào
                  if(in_array($k.'_'.$key,array_keys($data)))            
                  {
                  	$sotien=0;
                  	$sotien = $doanphi[$k] * $soluong[$key];
                  	$kq .= "<td style='text-align: center;'>".number_format($sotien,0,',','.')."<br>".date('d-m-Y',strtotime($data[$k.'_'.$key]))."<br><a href='".$this->webroot.$url['controller']."/".$url['action']."/".$k."_".$key.'/'.$url['params']."' >Xóa </a>"."</td>";
                  	//$kq .='<input type="hidden" id="check'.$k.'_'.$i.'" value="'.$k.'_'.$key.'"></input></td>';
                  }
                  else
                  {
                  		$sotien=0;
                  		$sotien = $doanphi[$k] * $soluong[$key];
	                    $kq=$kq. '<td><input type="checkbox" class="check" id="check'.$k.'_'.$i.'" name="data['.$model.'][dadong][]" value="'.$k.'_'.$key.'">
	                      </input>'.number_format($sotien,0,',','.').'</td>';
                  }
                  
                  
            endforeach;  
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    $kq.='<tr>';
    $kq.='<td colspan=3><b>Tổng Đoàn Phí Tháng</b></td>';
    $tong = 0;
     foreach($cot as $k=>$c):
       $kq=$kq. '<td id= tong'. $k .' style="text-align: center;">'. (empty($dathu[$k])?0:number_format($dathu[$k],0,',','.')) .'</td>';
       $kq=$kq. '<input type="hidden" id="dathu'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $kq=$kq. '<input type="hidden" id="dt'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $tong += empty($dathu[$k])?0:$dathu[$k];
     endforeach; 
    $kq.=' </tr>';
    $kq.='<tr>';
    $kq.='<td colspan=3><strong>Tổng Đoàn Phí Năm Học</strong></td>';
       $kq=$kq. '<td id="tongtd" style="text-align: center;" colspan='.$n.' >'.number_format($tong,0,',','.').'</td>';
       $kq=$kq. '<input type="hidden" id="tong"  value="'. $tong .'" />';
    $kq.=' </tr>';
    $kq.='</table>';
    return $kq;
    
    
  }

  function doanphkhoaexcel($model,$cot,$dong,$data=array(),$dathu=array(),$doanphi=array(),$soluong=array(),$tongtiens=array()){
	$n=count($cot);
    $m=count($dong);
    $kq='<input type="hidden" id="chidoan" value="'.$m.'" />';
	
    foreach ($soluong as $keysl => $valuesl) 
     {
     	$kq .='<input type="hidden" name=data['.$model.'][chidoan]['.$keysl.'] id="'.$keysl.'" value="'.$valuesl.'"></input>';
     }
     
    $kq.='<table id="tables" border =1>';  
    //for($i=-1;$i<$m;$i++){
    
    $kq.='<tr>';
	$kq.='<th rowspan="2">STT</th>';
    $kq.='<th rowspan="2">Chi đoàn</th>';
	$kq.='<th rowspan="2" style="text-align: center;">Đã đóng</th>';
    $kq.='<th colspan="12" style="text-align: center;">Tháng</th>';
    $kq.='</tr>';
    
    //$kq=$kq. '<th>Tháng</th>';
               
    foreach($cot as $k=>$c):
  
    	if (empty($doanphi[$k]))
         {
         	$doanp=0;
         }
         else
         {
         	$doanp=$doanphi[$k];
         }
        $kq=$kq. '<th><b><font color="#CC0909">'.
                      $c.'<br> ('. number_format($doanp,0,',','.').')</font></b></th>';
                      
		$kq=$kq. '<input type="hidden" id="thang'. $k .'" value="'.$doanp.'" name=data['.$model.'][doanphithang]['.$k.'] />';
                      
   endforeach; 
  
    $i=0;
	$j=1;
    foreach ($dong as $key=>$d):
        $kq.='<tr>';
        
			$kq.='<td>'.$j++.'</td>';
            $kq.='<td>'.$d.' <br> ( <b>'.$soluong[$key].'</b> đoàn viên)</td>';
            $kq.='<td>'.(isset($tongtiens[$key])?number_format($tongtiens[$key],0,',','.'):0).'</td>';
            foreach($cot as $k=>$c):
            
            //ghep id cua thang_mssv vao value
            //kiem tra nếu đã có dữ liệu, tức là có đóng đoàn phí thì check vào
                  if(in_array($k.'_'.$key,array_keys($data)))            
                  {
                  	$kq .= "<td style='text-align: center;'>".date('d-m-Y',strtotime($data[$k.'_'.$key]))."</td>";
                  	//$kq .='<input type="hidden" id="check'.$k.'_'.$i.'" value="'.$k.'_'.$key.'"></input></td>';
                  }
                  else
                    $kq=$kq. '<td></td>';
                  
                  
            endforeach;  
        
                    
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    $kq.='<tr>';
    $kq.='<td colspan="3"><b>Tổng Đoàn Phí Tháng</b></td>';
    $tong = 0;
     foreach($cot as $k=>$c):
       $kq=$kq. '<td id= tong'. $k .' style="text-align: center;">'. (empty($dathu[$k])?0:number_format($dathu[$k],0,',','.')) .'</td>';
       $kq=$kq. '<input type="hidden" id="dathu'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $kq=$kq. '<input type="hidden" id="dt'. $k .'" value="'. (empty($dathu[$k])?0:$dathu[$k]) .'" />';
       $tong += empty($dathu[$k])?0:$dathu[$k];
     endforeach; 
    $kq.=' </tr>';
    $kq.='<tr>';
    $kq.='<td colspan="3"><strong>Tổng Đoàn Phí Năm Học</strong></td>';
       $kq=$kq. '<td id="tongtd" style="text-align: center;" colspan='.$n.' >'.number_format($tong,0,',','.').'</td>';
       $kq=$kq. '<input type="hidden" id="tong"  value="'. $tong .'" />';
    $kq.=' </tr>';
    $kq.='</table>';
    return $kq;
    
    
  }
  
  function thu_chi($rows=array(),$cols=array(),$data=array())
  {
  		$colnum=count($cols);
    	$rownum=count($rows);
    	$result='<table id="tables">';  
    
    	$result.='<th></th>';
    
    	foreach($cols as $col_id => $display_c):
        	$result.='<th><b><font color="#CC0909">'.$display_c.'</font></b></th>';
   		endforeach; 
  
    	$i=0;   
    	foreach ($rows as $row_id=>$display_r):
        	$result.='<tr>';
        
            $result.='<td>'.$display_r.'</td>';
            for($j=0;$j<$colnum;$j++)
                  $result=$result. '<td>'. $data[$i][$j] .'</td>';
        
        $result.='</tr>';
        
        $i++;
        
     endforeach;  
    //}
    
    $result.='</table>';
    
    return $result;
  }

}
 ?>